package com.growthsee.rider.controller;

import com.growthsee.common.core.domain.AjaxResult;
import com.growthsee.rider.param.Signature;
import com.growthsee.rider.utils.BasicPathUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
@RequestMapping("/rider/signature")
public class SignatureController {
    @RequestMapping("getUgcUploadSign")
    public AjaxResult getUgcUploadSign() {
        Signature sign = new Signature();
        sign.setSecretId(BasicPathUtil.getSecretId());
        sign.setSecretKey(BasicPathUtil.getSecretKey());
        sign.setCurrentTime(System.currentTimeMillis() / 1000);
        sign.setRandom(new Random().nextInt(java.lang.Integer.MAX_VALUE));
        sign.setSignValidDuration(3600 * 24 * 2);

        try {
            String signature = sign.getUploadSignature();
            return AjaxResult.success(signature);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
    }
}
